package com.wanbatv.wangwangba.model.imple;

import android.content.Context;

import com.wanbatv.wangwangba.model.OnWechatListener;
import com.wanbatv.wangwangba.model.WechatModel;
import com.wanbatv.wangwangba.model.entity.WechatData;
import com.wanbatv.wangwangba.util.Config;
import com.wanbatv.wangwangba.util.GitWechatService;
import com.wanbatv.wangwangba.util.Util;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by 俞亚楠 on 2016/7/28.
 */
public class WechatModelImple implements WechatModel {
    Context context;
    public WechatModelImple(Context context){
        this.context=context.getApplicationContext();
    }
    Retrofit retrofitWechat =new Retrofit.Builder()
            .baseUrl(Config.httpUrlWechat())
            .addConverterFactory(GsonConverterFactory.create())
            .build();
    GitWechatService apiWechat=retrofitWechat.create(GitWechatService.class);
    @Override
    public void setWechatData(final OnWechatListener onWechatListener) {
        apiWechat.getWechat(Util.getDeviceId(context)).enqueue(new Callback<WechatData>() {
            @Override
            public void onResponse(Call<WechatData> call, Response<WechatData> response) {
                List<WechatData.MediaListBean> mediaListBeen=response.body().getMediaList();
                List<WechatData.UserListBean> userListBeen=response.body().getUserList();
                String qrUrl=response.body().getQrUrl();

                onWechatListener.onLoadWechatData(mediaListBeen,userListBeen,qrUrl);
            }

            @Override
            public void onFailure(Call<WechatData> call, Throwable t) {

            }
        });
    }
}
